#include "filemanager.h"

FileManager::FileManager() {


}

int createFile(QString filePath,const char * content) {
    QFile *file = new QFile(filePath);
    if(!file->open(QIODevice::WriteOnly)|QIODevice::Text) {
        qDebug() << file->errorString();
    }
    if(content) {
        file->write(content);
    }
    file->close();
}


int getFileInfo(QString filePath) {
    QFile file = QFile(filePath);
    if(!file.open(QIODevice::WriteOnly)|QIODevice::Text) {
        qDebug() << file.errorString();
    }
    QFileInfo info(file);
    QString absoluteFilePath =  info.absoluteFilePath();
    QString fileName = info.fileName();
    QString baseName = info.baseName();
    QString ext = info.suffix();
    qint64 size = info.size();
    QDateTime createdTime = info.birthTime();
    file.close();
}

int readFile(QString filePath,int pos, int count) {
    QFile file = QFile(filePath);
    if(!file.open(QIODevice::ReadOnly)|QIODevice::Text) {
        qDebug() << file.errorString();
        return -1;
    }
    file.seek(pos);
    file.read(count);
    file.close();
    return 0;
}

int writeFile(QString filePath,int pos, const char * content) {
    QFile file = QFile(filePath);
    if(!file.open(QIODevice::WriteOnly)|QIODevice::Text) {
        qDebug() << file.errorString();
        return -1;
    }
    file.seek(pos);
    file.write(content);
    file.close();
    return 0;
}
